package cn.tedu.knows.auth.security;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.InMemoryTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {

    // 定义jwt解密口令
    // 这个口令用于区分不同项目的jwt令牌
    // 只有口令正确才能解析jwt令牌
    private final String SINGING_KEY="pass";

    // 向Spring容器保存一个令牌生成器对象
    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(accessTokenConverter());
    }
    // Jwt令牌转换器
    @Bean
    public JwtAccessTokenConverter accessTokenConverter(){
        JwtAccessTokenConverter converter=
                new JwtAccessTokenConverter();
        // 设置解密口令并返回
        converter.setSigningKey(SINGING_KEY);
        return converter;
    }

}
